app.controller("catetoryGoodsCtrl",["$scope","$http","$rootScope",function($scope,$http,$rootScope){
    $rootScope.catetoryData = [];
    $rootScope.catetoryData = $rootScope.catetoryData.concat(JSON.parse(localStorage.getItem('carData')));
    $scope.sameData = [];
    $rootScope.addGoods = function(){
        var obj = {};
        var count = 1;
        if($scope.sameData.indexOf(this.$id) === -1){
            obj.name = this.$$watchers[2].last;
            obj.price = parseInt(this.$$watchers[1].last);
            obj.img = this.$$watchers[4].last;
            obj.praise = this.$$watchers[0].last;
            obj.sale = this.$$watchers[3].last;
            obj.count = count;
            $rootScope.catetoryData.push(obj);
            $scope.sameData.push(this.$id);
        }else{
            var indexGoods = $scope.sameData.indexOf(this.$id);
            obj.name = this.$$watchers[2].last;
            obj.price = parseInt(this.$$watchers[1].last);
            obj.img = this.$$watchers[4].last;
            obj.praise = this.$$watchers[0].last;
            obj.sale = this.$$watchers[3].last;
            obj.count = $rootScope.catetoryData[indexGoods].count + 1;
            $rootScope.catetoryData.splice(indexGoods,1,obj);
        }
        console.log($rootScope.catetoryData);
        // JSON.parse(localStorage.getItem('carData');
        // $scope.saveData = $rootScope.catetoryData.concat(JSON.parse(localStorage.getItem('carData')));
        // 清除本地存储记录
        localStorage.clear('carData');
        // 清除数组元素
        // $rootScope.catetoryData = [];
        // 存入本地存储
        localStorage.setItem('carData', JSON.stringify($rootScope.catetoryData));
    }

}])
